﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using PleaseORM.Extensions;
using PleaseORM.Structs;

namespace PleaseORM.Configuration
{
	internal class DomainConfiguration
	{
		protected Assembly DomainAssembly { get; set; }

		public IEnumerable<EntityInfo> EntityList { get; protected set; }

		public DomainConfiguration(string assemblyFile)
		{
			DomainAssembly = Assembly.LoadFrom(assemblyFile);
			EntityList = DomainAssembly.GetTypes()
										.Select(domain => new EntityInfo
											                  {
											                  	EntityName = domain.Name, 
																					EntityPluralName = domain.Name.MakePlural(), 
																					EntityFullName = domain.FullName
											                  });
		}

		public object CreateInstance(string fullName)
		{
			return DomainAssembly.CreateInstance(fullName);
		}
	}
}
